package com.hiwhitley.himei.contract.presenter;

import com.hiwhitley.himei.contract.DailyContract;
import com.hiwhitley.himei.entity.Video;
import com.hiwhitley.himei.mvpframe.rx.RxSchedulers;

import rx.Subscriber;

/**
 * Created by hiwhitley on 2016/9/24.
 */

public class DailyPresenter extends DailyContract.Presenter {

    @Override
    public void loadDaily(String url) {
        mRxManager.add(mModel.getDaily(url)
                .compose(RxSchedulers.io_main())
                .subscribe(new Subscriber<Video>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.onInternetError();
                        mView.onRequestEnd();
                    }

                    @Override
                    public void onNext(Video video) {
                        for (Video.IssueListBean issueListBean : video.getIssueList()) {
                            mView.showDaily(issueListBean.getItemList(), video.getNextPageUrl());
                        }
                    }
                })

        );
    }
}
